package com.define.ssh.dao.impl;

import java.math.BigInteger;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.define.ssh.dao.CompdeptDao;
import com.define.ssh.model.Compdept;
import com.define.ssh.model.Deptuser;
import com.define.ssh.util.Pager;

@Repository("compdeptDaoImpl")
public class CompdeptDaoImpl extends BaseDaoImpl<Compdept, Integer> implements
		CompdeptDao {

	/**
	 * 查询部门有没子部门
	 * 
	 * @param pid
	 * @return
	 */
	@Override
	public Integer getDeptCount(Integer pid) {
		final String sql = "select count(*) from  compdept where pid=" + pid;
		Object  cdCount=getSession().createSQLQuery(sql).uniqueResult();
		return Integer.valueOf(cdCount.toString());
	}

	@Override
	public int getTotalByDeptId(int id) {
		final String sql = "select count(*) from  user ui where ui.id in (select du.userid from deptuser du where du.deptid="+id+")";
		return ((BigInteger) getSession().createSQLQuery(sql).uniqueResult()).intValue();
	}
	
	public void delete1(int id){
		final String sql = "update deptuser set deptid=99999 where deptid="+id;
		getSession().createSQLQuery(sql).executeUpdate();
	}

	
	


}
